fn main() {
    let s = String::from("hello world");

    let slice = first_word(&s);

    println!("{}", slice);

    let slice = first_word(&s[6..11]);

    println!("{}", slice);
}

// fn first_word(s: &String) -> &str {
fn first_word(s: &str) -> &str {    // 更具有通用性
    let bytes = s.as_bytes();

    for (i, &item) in bytes.iter().enumerate() {
        if item == b' ' {
            return &s[0..i];
        }
    }

    &s[..]
}
